package labuladong.第四章;

import leetcode.ListNode;

public class RemoveDuplicate {
    public static void main(String[] args) {
        int[] arr = {0, 1, 2, 2, 3, 3, 3, 4, 4, 4, 4};
        System.out.println(removeDuplicate(arr));
    }

    public static int removeDuplicate(int[] nums) {
        int n = nums.length;
        if(n <= 1) {
            return n;
        }
        int slow = 0, fast = 1;
        while (fast < n) {
            if(nums[slow] != nums[fast]) {
                slow ++;
                nums[slow] = nums[fast];
            }
            fast ++;
        }
        return slow+1;
    }

    public static ListNode removeDuplicateNode(ListNode head) {
        if (head == null) {
            return null;
        }

        ListNode slow = head, fast = head.next;
        while (fast != null) {
            if(fast.val != slow.val) {
                slow.next = fast;
                slow = slow.next;
            }
            fast = fast.next;
        }
        return head;
    }
}
